package com.yao.sample.pattern.observer;

import java.util.Observable;
import java.util.Observer;

public class GeneralDisplay implements Observer,DisplayElement{
	Observable subject;
	private float temperature;
	private float humidity;
	
	public GeneralDisplay(Observable subject) {
		this.subject = subject;
		subject.addObserver(this);
	}
	
	@Override
	public void display() {
		System.out.println("temperature:"+temperature);
		System.out.println("humidity:"+humidity);
	}

	@Override
	public void update(Observable o, Object arg) {
		if(o instanceof WeatherData) {
			this.humidity = ((WeatherData) o).getHumidity();
			this.temperature = ((WeatherData) o).getTemperature();
			display();
		}
	}

}
